from lib.resource_management import *
from lib.resource_management.core.resources.system import Execute
from lib.resource_management.libraries.script.script import Script


class Hue(Script):
    def install(self, env):
        import params
        env.set_params(params)
        # 删除现有的软连接
        Execute('rm -rf /usr/hdp/current/hue')
        # 删除现有的Hue
        Execute('rm -rf {0}/hue*'.format(params.hdp_base_dir))
        # 从yum源拉取源码包
        Execute('wget {0} -O hue.tar.gz'.format(params.hue_download_url))
        # 解压缩源码包
        Execute('tar -zxvf hue.tar.gz -C {0} rm -rf hue.tar.gz'.format(params.hdp_base_dir))
        # hue安装目录改名
        Execute('mv {0}/hue* {1}'.format(params.hdp_base_dir, params.hue_base_dir))
        # 创建目录软链至current
        Execute('ln -s {0} /usr/hdp/current/elastic'.format(params.hue_base_dir))

        Logger.info("Get source package complete")

    def start(self, env):
        print('start')
        #

    def stop(self, env):
        print('stop')

    def configure(self, env):
        print('configure')

    def status(self, env):
        print('status')


if __name__ == "__main__":
  Hue().execute()

